import { createRouter, createWebHashHistory } from 'vue-router'
import LoginRoutes from '@/views/Login/LoginRouter'
import HomeRoutes from '@/views/Home/HomeRoutes'
import ErrorRoutes from '@/views/Error/ErrorRoutes'
// import { useUserinfoStore } from '@/stores' //??????
import { ElMessage } from 'element-plus'

export const routes: any = [
  {
    path: '/',
    redirect: '/login'
  },
  ...LoginRoutes,
  ...HomeRoutes,
  ...ErrorRoutes
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

//路由前置守卫
router.beforeEach((to) => {
  const isLogin = localStorage.getItem('userToken')
  if (to.path === 'home' && !isLogin) {
    ElMessage.warning('请先登录!');
    return { path: '/' }
  }
})


export default router
